package com.wlz.workqueue;

import com.google.gson.Gson;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.wlz.utils.RabbitUtils;
import lombok.extern.slf4j.Slf4j;

/**
 *  工作队列（公平性） 模式  -- 发送者
 * @author wlz
 * @date 2022-06-27  9:51 下午
 */
@Slf4j
public class OrderSystem {

    public static void main(String[] args) throws Exception{

        Connection connection = RabbitUtils.getConnection();

        Channel channel = connection.createChannel();

        String queueName = "wlz_sms";

        channel.queueDeclare(queueName, false, false, false, null);


        for (int i = 1; i <= 100; i++) {
            Sms sms = new Sms("乘客" + i, "1380000000" + i, "你的车票已预订成");
            String jsonSms = new Gson().toJson(sms);
            channel.basicPublish("", queueName, null, jsonSms.getBytes());
        }

        log.info(" 工作队列 : {} , 消息发送成功", queueName);

        channel.close();;
        connection.close();
    }
}
